package ProjectViewer;

import javax.swing.DefaultListModel;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;


import ClassData.FieldInfo;

public class Panel_FieldList extends JScrollPane implements ListSelectionListener{

	/**
		 * 
		 */
		private static final long serialVersionUID = 1L;

JList myFieldsList;	
DefaultListModel mylistModel;
Panel_FieldData myDataPanel;

public Panel_FieldList (FieldInfo [] listOfFields,Panel_FieldData myDataPanel)
{
	int counter;

	this.myDataPanel=myDataPanel;
	mylistModel = new DefaultListModel();
	

	
	for (counter=0;counter<listOfFields.length;counter++)
		{
		mylistModel.addElement(listOfFields[counter]);
		}
	
	myFieldsList = new JList(mylistModel);
	myFieldsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
	myFieldsList.addListSelectionListener(this);
	
	getViewport().setView(myFieldsList);
}


@Override
public void valueChanged(ListSelectionEvent arg0)
{
	int index;
	FieldInfo myFieldData;
	

	index=myFieldsList.getSelectedIndex(); //.getFirstIndex();
	myFieldData=(FieldInfo)mylistModel.get(index);
	
	myDataPanel.displayClass(myFieldData);
	// TODO Auto-generated method stub
	
}
	


}
